#include "VxIrrLib.h"

///This class sychronizes the world transform between Bullet rigid bodies and their accompanying Irrlicht nodes
//=== constructor ===//
IrrPhysMotionState::IrrPhysMotionState( irr::scene::ISceneNode* irrNode, float f32PhysWorldScaling)
	: m_irrNode(irrNode)
	, m_f32PhysWorldScaling(f32PhysWorldScaling)
{
}
///synchronizes world transform from user to physics
void IrrPhysMotionState::getWorldTransform(btTransform& centerOfMassWorldTrans ) const 
{
	centerOfMassWorldTrans = m_graphicsWorldTrans;
	const btVector3& Point = m_graphicsWorldTrans.getOrigin();
	//log_msg( 0, "IrrPhysMotionState::setWorldTransform: Pos X=%3.2f Y=%3.2f, Y=%3.2f \n",
	//		(irr::f32)Point[0], (irr::f32)Point[1], (irr::f32)Point[2] );
}

///synchronizes world transform from physics to user
///Bullet only calls the update of worldtransform for active objects
void IrrPhysMotionState::setWorldTransform(const btTransform& centerOfMassWorldTrans)
{
	//numUpdatedBodies++;
	m_startWorldTrans = centerOfMassWorldTrans;
	m_graphicsWorldTrans = centerOfMassWorldTrans;

	const btVector3& Point = centerOfMassWorldTrans.getOrigin();
	//log_msg( 0, "IrrPhysMotionState::setWorldTransform: Pos X=%3.2f Y=%3.2f, Y=%3.2f \n",
	//		(irr::f32)Point[0], (irr::f32)Point[1], (irr::f32)Point[2] );
	m_irrNode->setPosition(irr::core::vector3df((irr::f32)Point[0], (irr::f32)Point[1], (irr::f32)Point[2]) );

	// Set rotation
	//btVector3 EulerRotation;
	//IrrPhysQuaternionToEuler(centerOfMassWorldTrans.getRotation(), EulerRotation);
	//m_irrNode->setRotation( irr::core::vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]) );
}


